package com.example.demotest;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

/**
 * @version 1.0.0
 * @className: DelayedDemo
 * @description:
 * @author: zhangjunfa
 * @date: 2023/6/5 15:19
 */
public class DelayedDemo implements Delayed {
    private final String taskContent;

    private final Long triggerTime;

    public DelayedDemo(String taskContent, Long triggerTime) {
        this.taskContent = taskContent;
        this.triggerTime = triggerTime;
    }

    public String getTaskContent() {
        return taskContent;
    }

    public Long getTriggerTime() {
        return triggerTime;
    }

    @Override
    public long getDelay(TimeUnit unit) {
        return unit.convert(triggerTime - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
    }


    @Override
    public int compareTo(Delayed o) {
        return this.triggerTime.compareTo(((DelayedDemo) o).triggerTime);
    }
}
